package com.research.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.research.common.R;
import com.research.entity.Department;
import com.research.service.DepartmentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/*前端控制器*/
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Resource
    private DepartmentService departmentService;

    @GetMapping("list")
    public R list(String keyword) {
        return R.success(departmentService.list(
                new QueryWrapper<Department>().like(keyword != null, "department_name", keyword)
        ));
    }

    @PostMapping("save")
    public R save(@RequestBody Department department) {
        return R.success(departmentService.save(department));
    }

    @PostMapping("update")
    public R update(@RequestBody Department department) {
        return R.success(departmentService.updateById(department));
    }

    @PostMapping("delete")
    public R delete(Integer id) {
        return R.success(departmentService.removeById(id));
    }

    @GetMapping("detail")
    public R detail(Integer id) {
        return R.success(departmentService.getById(id));
    }
}

